// pages/initGroup/initGroup.js
import {getPhoneBooksByGroup} from '../util/request.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:2,
    indexList: {},
    phoneGroup:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    
    const res=await getPhoneBooksByGroup()
    console.log(res)
    let map = new Map(Object.entries(res))
    let indexs=[]
    let phoneGroup=[]
    for (let index of map.keys()) {
      indexs.push(index)
      phoneGroup.push(map.get(index))
    }
    this.setData({
      indexList:indexs,
      phoneGroup:phoneGroup
    })
    console.log(this.data.phoneGroup)
  },

  onChange(event) {
    if(this.data.active==event.detail)
      return
    if(event.detail==0){
      wx.navigateTo({
        url: '../index/index',
      })
    }else if(event.detail==1){
      wx.navigateTo({
        url: '../new/new',
      })
    }else{
      wx.navigateTo({
        url: '../initGroup/initGroup',
      })
    }
  }
})